import { http } from "../http";

const baseUrl = "/api/dms/messages";

// 消息状态枚举
export enum MessageStatus {
  PROCESSED = "PROCESSED", // 已处理
  UNPROCESSED = "UNPROCESSED", // 未处理
  NO_ACTION_REQUIRED = "NO_ACTION_REQUIRED", // 无需处理
}

// 消息类型枚举
export enum MessageType {
  DEVICE_ALARM = "DEVICE_ALARM", // 设备告警消息
  RESERVATION_APPROVAL = "RESERVATION_APPROVAL", // 设备预约审批消息
  SYSTEM_NOTIFICATION = "SYSTEM_NOTIFICATION", // 系统通知消息
}

// 消息范围
export enum MessageScope {
  PLATFORM_WIDE = "PLATFORM_WIDE", // 全平台
  TARGETED_USERS = "TARGETED_USERS", // 指定用户范围
}

// 消息级别
export enum MessagePriority {
  URGENT = "URGENT", // 紧急
  REMINDER = "REMINDER", // 提醒
}

// 系统通知消息接口
export interface SystemMessageType {
  id: string;
  type: MessageType | null;
  scope: MessageScope | null;
  description: string;
  priority: MessagePriority | null;
  status: MessageStatus | null;
  createdAt: string | null;
}

// 分页获取消息请求参数
export interface GetMessagesRequestType {
  type: MessageType | null;
  scope: MessageScope | null;
  priority: MessagePriority | null;
  status: MessageStatus | null;
  pageNum: number;
  pageSize: number;
}

// 添加消息请求参数
export interface AddMessageRequestType {
  type: MessageType;
  scope: MessageScope;
  description: string;
  priority: MessagePriority;
}

// 处理消息请求参数
export interface ProcessMessageRequestType {
  id: string;
  status: MessageStatus;
  remark: string;
}

/**
 * @description 分页获取系统通知消息
 * @param params 分页和筛选参数
 */
export const getMessagesAPI = (params: GetMessagesRequestType) => {
  return http.post(`${baseUrl}/getMessages`, params);
};

/**
 * @description 添加系统通知消息
 * @param params 消息内容参数
 */
export const addMessageAPI = (params: AddMessageRequestType) => {
  return http.post(`${baseUrl}/addMessage`, params);
};

/**
 * @description 处理通知消息
 * @param params 处理参数
 */
export const processMessageAPI = (params: ProcessMessageRequestType) => {
  return http.put(`${baseUrl}/processMessage`, params);
};

// 删除通知消息
export const deleteMessageAPI = (id: string) => {
  return http.delete(`${baseUrl}/deleteMessage/${id}`);
};
